import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;

public class crossTalker {
	
	private static String path = "/var/www/upload/crosstalk/";
	private int _bookId = -1;
	
	crossTalker(int bookId) {
		_bookId = bookId;
	}
	
	public String addPDF() {
		String fileName = makeFileName();
		File myFile = new File(path + fileName);
		if(	myFile.canWrite() ) {
			try {
				BufferedWriter br = new BufferedWriter(new FileWriter(myFile));
				br.write(_bookId);
				br.close();
			} catch (IOException e) {
				System.out.println("Couldn't write to the file PDF");
				e.printStackTrace();
			}
		}
		return fileName;
	}
	
	public String addImg() {
		String fileName = makeFileName();
		File myFile = new File(path + fileName);
		
			try {
				myFile.createNewFile();
				FileWriter mFWriter = new FileWriter(myFile);
				BufferedWriter br = new BufferedWriter(mFWriter);
				br.write(_bookId);
				br.close();
			} catch (IOException e) {
				System.out.println("Couldn't write to the file JPG");
				e.printStackTrace();
			}
		return fileName;
	}

	private static String makeFileName() {
		return UUID.randomUUID().toString();
	}
	
	public void close(String fileName) {
		File myFile = new File(path+fileName);
		myFile.delete();
	}
}
